package com.hanamaki.general;

public class GeneralDemo01 {

    // 打印数组的方法
    // 如果方法是个泛型泛型方法  方法的实际参数 的数据类型必须是包装类
    public static<T> void printArray(T[] a) {

        for (int i = 0; i < a.length; i++) {
            if (i == 0) {
                System.out.print("[");
            }
            if (i == a.length - 1) {
                System.out.print(a[i] + "]");
            } else {
                System.out.print(a[i] + ", ");
            }

        }

        System.out.println();
    }

    public <T> void printArray1(T[] a) {

        for (int i = 0; i < a.length; i++) {
            if (i == 0) {
                System.out.print("[");
            }
            if (i == a.length - 1) {
                System.out.print(a[i] + "]");
            } else {
                System.out.print(a[i] + ", ");
            }

        }

        System.out.println();
    }

    public static void main(String[] args) {
        Integer[] arr = {23, 435, 76, 76, 43, 32, 45, 56, 67};
        printArray(arr);

        Double[] dou = {23.0, 435.0, 76.0, 76.0, 43.0, 32.0, 45.0, 56.0, 67.0};
        printArray(dou);

        String[] str = {"12", "78", "56"};
        printArray(str);

    }
}
